from flask import Flask
from models.model import db
from flask_cors import CORS
from views.user import user_bp   # 从蓝图文件里面导入蓝图对象
from views.animal import animal_bp
from views.top_up import top_bp



def create_app(config):
    flask_app = Flask(__name__)

    # 加载配置文件
    flask_app.config.from_object(config)

    # 初始化db
    db.init_app(flask_app)

    # 跨域
    cors = CORS(flask_app)

    # TODO 注册蓝图
    flask_app.register_blueprint(user_bp)
    flask_app.register_blueprint(animal_bp)
    flask_app.register_blueprint(top_bp)

    return flask_app
